package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.SoulQuestionOptions;
import com.tanhua.dubbo.api.SoulQuestionOptionsApi;
import com.tanhua.dubbo.mapper.SoulQuestionOptionsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class SoulQuestionOptionsImpl implements SoulQuestionOptionsApi {
    @Autowired
    private SoulQuestionOptionsMapper soulQuestionOptionsMapper;
    
    /**
     * 添加
     *
     * @param soulQuestionOptions
     */
    @Override
    public void save(SoulQuestionOptions soulQuestionOptions) {
        soulQuestionOptionsMapper.insert(soulQuestionOptions);
        
    }
    
    /**
     * 根据问题内容id查询问题选项
     *
     * @param contentId
     */
    @Override
    public List<SoulQuestionOptions> findByContentId(Long contentId) {
        QueryWrapper<SoulQuestionOptions> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("content_id", contentId);
        
        return soulQuestionOptionsMapper.selectList(queryWrapper);
    }
    
    /**
     * 根据问题id和选项id获取分数
     *
     * @param contentId
     * @param optionId
     */
    @Override
    public int findScore(Long contentId, String optionId) {
        QueryWrapper<SoulQuestionOptions> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("content_id", contentId).eq("option_id", optionId);
        return soulQuestionOptionsMapper.selectOne(queryWrapper).getOptionScore();
    }
}
